/*
 * Copyright 2010 Joshua Smith and Nelson Llewellyn
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package norse.server.resources.legacy;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

/**
 * REST Web Service
 */
@Path("staticfile")
public class StaticFileResource {
    @Context
    private UriInfo context;

    /** Creates a new instance of StaticFileResource */
    public StaticFileResource() {
    }

    /**
     * Retrieves representation of an instance of norse.server.StaticFileResource
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("application/xml")
    public String getXml()
    {
        StringBuilder returnVal = new StringBuilder();

        BufferedReader buffRead = null;;
        try
        {
            InputStreamReader isRead = new InputStreamReader(
                    StaticFileResource.class.getResourceAsStream(
                    "/norse/temp/NmapScanResultsFormatted.xml"));
            buffRead = new BufferedReader(isRead);

            String currLine;
            while((currLine = buffRead.readLine()) != null)
            {
                returnVal.append(currLine + "\n");
            }

            return returnVal.toString();
        }
        catch(Exception error)
        {
            return "<html><body><h1>Error in resource: " + error.getMessage()
                    + "</h1></body></html>";
        }
        finally
        {
            if(buffRead != null)
            {
                try
                {
                    buffRead.close();
                }
                catch(Exception error)
                {
                   ; //Ignore
                }
            }
        }

    }

    /**
     * PUT method for updating or creating an instance of StaticFileResource
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/xml")
    public void putXml(String content)
    {
    }
}
